import query from '@dfeidao/atom-nodejs/db/query';

// import { isBoolean } from 'util';
// import { systemid } from './config';

interface Message {
	productid: string;
	role_no: string;
}

interface Data {
	pk_val: string;
	datagroup_no: string;
}
export default async function atom(msg: Message, action_id: string, session_id: string, spaceid: string) {
	const productid = msg.productid;
	const role_no = msg.role_no;
	const systemid1 = '12';
	const { exec, prepare } = query(action_id, session_id, systemid1);
	const { exec: e1, prepare: p1 } = query(action_id, session_id, systemid1);
	p1('pub_role_allot', ['pk_val', 'search_field_val'], { productid, role_no }, 200, 1, [], []);
	const [data] = await e1<Data>();
	const arr = data.map((v) => {
		return v.pk_val;
	});
	prepare('auth_datagroup', ['datagroup_no', 'datagroup_name'], { productid }, 200, 1, [], []);
	const [data1] = await exec<Data>();
	const data2 = data1.filter((v) => {
		return arr.indexOf(v.datagroup_no) === -1;
	});
	return data2;
}
